import japa.parser.JavaParser; 
 import japa.parser.ast.CompilationUnit; 
 import japa.parser.ast.body.FieldDeclaration; 
 import japa.parser.ast.body.MethodDeclaration; 
 import japa.parser.ast.body.VariableDeclarator; 
 import japa.parser.ast.visitor.VoidVisitorAdapter; 
  
 import java.io.BufferedWriter; 
 import java.io.FileInputStream; 
 import java.io.FileWriter; 
 import java.io.IOException; 
 import java.util.List; 
 public  class CommonPropertiesParser{  
         static BufferedWriter first;     
         static BufferedWriter second;    
          
         public void parseMultipleClasses(String[] filenames, int numFiles) throws Exception { 
        
              CompilationUnit[] cu=new CompilationUnit[1000]; 
              FileInputStream[] in=new FileInputStream[1000]; 
          
             for(int j=0;j<numFiles;j++){ 
                  in[j] = new FileInputStream(filenames[j]);  
              
             } 
                
              
             first = new BufferedWriter(new FileWriter("InfoFiles/Methods1.txt")); 
         second = new BufferedWriter(new FileWriter("InfoFiles/Members1.txt")); 
          
         try { 
                  
                 for(int i=0;i<numFiles;i++){ 
                          
                   cu[i]=JavaParser.parse(in[i]);  
                  
                 } 
                  
                  
                  
              
         } 
         finally {  
              
                 for(int i=0;i<numFiles;i++){ 
                          
                   in[i].close();  
                  
                 } 
                  
       } 
          
         for(int i=0;i<numFiles;i++){ 
                  
                  new MethodVisitor().visit(cu[i], null); 
              first.write("End of class"); 
              first.newLine(); 
              new FieldVisitor().visit(cu[i], null); 
              second.write("End of Class"); 
              second.newLine(); 
          
         } 
          
         first.close(); 
         second.close(); 
        /*MultiClassConexp conexp=new MultiClassConexp(); 
        conexp.generateInput("conexpInputFormat1.txt",numFiles);*/ 
          
     }  
         private static class MethodVisitor extends VoidVisitorAdapter<Object> {  
                 public void visit(MethodDeclaration n, Object arg) {            
                          
                         try {                                    
                                         first.write(n.getName()+"()"); 
                                         first.newLine(); 
                                     
                            
                                 } 
                         catch (IOException e) {                  
                                         e.printStackTrace(); 
                                 } 
                      
                      
                 }  
                  
             }  
             
  
           private static class FieldVisitor extends VoidVisitorAdapter<Object> {  
                 public void visit(FieldDeclaration n1, Object arg) {            
                           List<VariableDeclarator>  aa = n1.getVariables(); 
                         try {                             
                             String fieldName=aa.get(0).toString(); 
                              
                             if(fieldName.indexOf(" ")>=0) 
                             {    
                                 second.write(fieldName.substring(0, fieldName.indexOf(" "))); 
                             } 
                             else if(fieldName.indexOf("=")>=0) 
                             { 
                                 second.write(fieldName.substring(0, fieldName.indexOf("="))); 
                             } 
                             else{ 
                                 second.write(fieldName); 
                             } 
                                         second.newLine(); 
                         } 
                         catch (IOException e) {                  
                                         e.printStackTrace(); 
                                 } 
                      
                      
                 }  
                  
             }  
             
  
  
 }   
            
            
      